#pragma once
#include <string>
#include "Object.h"
namespace RayTrace{

class CScene;
class C3DS_Loader
{
public:
	C3DS_Loader(void);
	~C3DS_Loader(void);
	bool Load(std::string filename,CScene * Scene);

private:
	struct ChunkHeader {
		unsigned short id;	// The chunk's id
		unsigned long  len;	// The lenght of the chunk
	};

	CScene *pScene;
	//char *modelname;		// The name of the model
	//char *path;				// The path of the model
	FILE *bin3ds;			// The binary 3ds file
	std::string mPath;

	void IntColorChunkProcessor(long length, long findex, vector4& vec4);
	void FloatColorChunkProcessor(long length, long findex, vector4& vec4);
	// Processes the Main Chunk that all the other chunks exist is
	void MainChunkProcessor(long length, long findex);
	// Processes the model's info
	void EditChunkProcessor(long length, long findex);

	// Processes the model's materials
	void MaterialChunkProcessor(long length, long findex, CMaterial& mat);
	// Processes the names of the materials
	void MaterialNameChunkProcessor(long length, long findex, CMaterial& mat);
	// Processes the material's diffuse color
//	void DiffuseColorChunkProcessor(long length, long findex, int matindex);
	// Processes the material's texture maps
	void TextureMapChunkProcessor(long length, long findex,CMaterial &mat);
	// Processes the names of the textures and load the textures
	void MapNameChunkProcessor(long length, long findex, CMaterial &mat);

	// Processes the model's geometry
	void ObjectChunkProcessor(long length, long findex,Object& obj);
	// Processes the triangles of the model
	void TriangularMeshChunkProcessor(long length, long findex, Object& obj);
	// Processes the vertices of the model and loads them
	void VertexListChunkProcessor(long length, long findex, Object& obj);
	// Processes the texture cordiantes of the vertices and loads them
	void TexCoordsChunkProcessor(long length, long findex, Object& obj);
	// Processes the faces of the model and loads the faces
	void FacesDescriptionChunkProcessor(long length, long findex,Object& obj);
	// Processes the materials of the faces and splits them up by material
	void FacesMaterialsListChunkProcessor(long length, long findex, Object& obj, int subfacesindex);

	//void IntChunkProcessor(long length, long findex, int&);
	//void FloatChunkProcessor(long length, long findex, float&);

	void PercentChunkProcessor(long length, long findex,float& );
	// Calculates the normals of the vertices by averaging
	// the normals of the faces that use that vertex
	void CalculateNormals();

	void ColorChunkProcessor(long length, long findex,vector4 & vec4);
};

}